package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.ResourceBks;
import com.example.mybatisplus.mapper.ResourceBksMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.ResourceBksService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zjy
 * @since 2024-07-21
 */
@Service
public class ResourceBksServiceImpl extends ServiceImpl<ResourceBksMapper, ResourceBks> implements ResourceBksService {

    @Override
    public Page<ResourceBks> pageList(ResourceBks resourceBks, PageDTO dto) {
        QueryWrapper<ResourceBks> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(resourceBks.getParkBks())){
            wrapper.like("park_bks",resourceBks.getParkBks());
        }
        if (Objects.nonNull(resourceBks.getBuildingBks())){
                wrapper.eq("building_bks",resourceBks.getBuildingBks());
        }
        if (Objects.nonNull(resourceBks.getFloorBks())){
            wrapper.eq("floor_bks",resourceBks.getFloorBks());
        }
        if (Objects.nonNull(resourceBks.getRoomBks())){
            wrapper.eq("room_bks",resourceBks.getRoomBks());
        }
        if (Objects.nonNull(resourceBks.getBedBks())){
            wrapper.eq("bed_bks",resourceBks.getBedBks());
        }
        if (Objects.nonNull(resourceBks.getPriceBks())){
            wrapper.eq("price_bks",resourceBks.getPriceBks());
        }
        wrapper.eq("is_enable",true);
        Page<ResourceBks> page = new Page<>();
        page.setCurrent(dto.getPageNo()).setSize(dto.getPagesize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }
}
